import { _decorator, Component, Node, Label, Sprite, Button, UIOpacity } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('LevelItem')
export class LevelItem extends Component {
    @property(Node)
    starImg !:Node;
    @property(Node)
    itemBg !:Node;
    @property(Node)
    levelTxt !:Node;

    _callfunc : any;

    onLoad () {
    }

    showStar (isOpen: any, starCount: any, levelImgAtlas: any, level: any) {
        this.itemBg.attr({"_level_" : level});
        if(isOpen){
           this.itemBg.getComponent(Sprite)!.spriteFrame = levelImgAtlas.getSpriteFrame("pass_bg");
           this.starImg.active = true;
           this.starImg.getComponent(Sprite)!.spriteFrame = levelImgAtlas.getSpriteFrame("point" + starCount);
           this.levelTxt.getComponent(UIOpacity)!.opacity = 255;
           this.itemBg.getComponent(Button)!.interactable = true;
        }
        else{
           this.itemBg.getComponent(Sprite)!.spriteFrame = levelImgAtlas.getSpriteFrame("lock");
           this.starImg.active = false;
           this.levelTxt.getComponent(UIOpacity)!.opacity = 125;
           this.itemBg.getComponent(Button)!.interactable = false;
        }
        this.levelTxt.getComponent(Label)!.string = level;
    }

    btnCallBack (event: any, customEventData: any) {
        if(this._callfunc){
            // @ts-ignore
            this._callfunc(this.itemBg['_level_']);
        }
    }

    levelFunc (callfunc: any) {
        this._callfunc = callfunc;
    }
}
